<?php $this->fetch('public/head') ?>
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class=""><a href="<?php echo url('index') ?>">轮播图管理</a></li>
        <li class=""><a href="<?php echo url('add') ?>">添加轮播图</a></li>
        <li class="layui-this">编辑轮播图</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form form-container" action="<?php echo url('update') ?>" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">所属分类</label>
                    <div class="layui-input-block">
                        <select name="nid" lay-verify="required">
                            <?php foreach($class_type as $k=>$v): ?>
                            <option value="<?php echo $k ?>" <?php if($k==$rows['nid']){echo 'selected';} ?>><?php echo $v ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" value="<?php echo $rows['title'] ?>" required  lay-verify="required" placeholder="请输入名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">说明</label>
                    <div class="layui-input-block">
                        <textarea name="content" placeholder="（选填）请输入说明" id="description" class="layui-textarea"><?php echo $rows['content'] ?></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">图片</label>
                    <div class="layui-upload">
                        <input type="text" name="img_url" value="<?php echo $rows['img_url'] ?>" class="layui-input layui-input-inline">
                        <button type="button" class="layui-btn _img_url"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                        <img class="layui-upload-img" src="<?php echo $rows['img_url'] ?>" height="38" data-expander='default,diamond,turn3d,flip3d,rotate,fade'>
                        仅允许上传jpg,png,gif,jpeg格式，推荐尺寸318*192
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接</label>
                    <div class="layui-input-block">
                        <input type="text" name="link" value="<?php echo $rows['link'] ?>" placeholder="（选填）请输入链接" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">打开方式</label>
                    <div class="layui-input-block">
                        <input type="radio" name="target" value="_self" title="默认" <?php if($rows['target']=='_self'){echo 'checked="checked"';} ?>>
                        <input type="radio" name="target" value="0_blank" title="新窗口" <?php if($rows['target']=='_blank'){echo 'checked="checked"';} ?>>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="is_show" value="1" title="显示" <?php if($rows['is_show']==1){echo 'checked="checked"';} ?>>
                        <input type="radio" name="is_show" value="0" title="隐藏" <?php if($rows['is_show']==0){echo 'checked="checked"';} ?>>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="sort" value="<?php echo $rows['sort'] ?>" required  lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">发布时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="add_time" value="<?php echo $rows['add_time'] ?>" class="layui-input datetime">
                    </div>
                </div>
                <input type="hidden" name="id" value="<?php echo $rows['id'] ?>">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<?php $this->fetch('public/script') ?>

<script type="text/javascript">
layui.use('upload', function(){
  var upload = layui.upload;
  //多图片上传
  upload.render({
    elem: '#img2',
    url: '<?php echo url('hsjson/upload') ?>',
    multiple: true,
    done: function(res){
        //如果上传失败
        if(res.error > 0){
            return layer.msg(res.message);
        }
        //上传完毕
        photoListItem = '<div class="photo-list"><input type="text" name="tit[]" value="" class="layui-input layui-input-inline"><input type="text" name="photo[]" value="' + res.url + '" class="layui-input layui-input-inline">';
        photoListItem += '<button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button>';
        photoListItem += '&nbsp;<img src="'+ res.url +'" height="38" class="layui-upload-img"></div>'
        $('#photo-container').append(photoListItem).on('click', '.remove-photo-btn', function () {
            $(this).parent('.photo-list').remove();
        });
    }
  });
})
$('#photo-container').on('click', '.remove-photo-btn', function () {
    $(this).parent('.photo-list').remove();
});
</script>